home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / RCSC.ZIP / BIN / 8086.M4 < prev    next >
Text File  |  1997-01-12  |  7KB  |  382 lines

  1. divert(-1)
  2. #********************************************************************
  3. #
  4. #M4 definitions for implementing the Retargetable Concurrent Small C
  5. #virtual machine on the 80x86
  6. #Copyright 1997 Andy W. K. Yuen
  7. #
  8. #********************************************************************
  9. #
  10. #RCSC pseudo instructions
  11. #
  12. #********************************************************************
  13. define(`CSCEXTRN',
  14. `extrn __eq: near
  15. extrn __ne: near
  16. extrn __le: near
  17. extrn __lt: near
  18. extrn __ge: near
  19. extrn __gt: near
  20. extrn __ule: near
  21. extrn __ult: near
  22. extrn __uge: near
  23. extrn __ugt: near
  24. extrn __lneg: near
  25. extrn __switch: near')
  26.  
  27. define(`CSCTERM',
  28. `extrn __cscinit:NEAR
  29. MNTRSEG SEGMENT PUBLIC
  30. dw 1a1ah
  31. MNTRSEG ENDS
  32. TASKSEG SEGMENT PUBLIC
  33. dw 1a1ah
  34. TASKSEG ENDS
  35. INTRSEG SEGMENT PUBLIC
  36. dw 1a1ah
  37. INTRSEG ENDS')
  38.  
  39. define(`EXTERNAL',
  40. `extrn $1:$2')
  41.  
  42. define(`TOSEG',
  43. `define(`CURSEG', $1) ifelse($1, 1, 
  44. `DATA SEGMENT PUBLIC',
  45. `CODE SEGMENT PUBLIC
  46. ASSUME CS:CODE, SS:DATA, DS:DATA')')
  47.  
  48. define(`ENDSEG',
  49. `ifelse($1, 1, DATA ENDS, CODE ENDS)')
  50.  
  51. define(`DECLPUBLIC',
  52. `ifelse(CURSEG, 2, 
  53. `PUBLIC $1
  54. $1:', 
  55. `PUBLIC $1
  56. DECLARE($1)')')
  57.  
  58. define(`DECLARE', 
  59. `define(`LABELON', 1)
  60. DECLAREMEM($1,')dnl
  61.  
  62. define(`REFm', 
  63. `define(`LABELON', 1)
  64. REFmMEM($1,')dnl
  65.  
  66. define(`SHADOW', `')
  67. define(`MODULENAME', `')
  68. define(`BEGINLIT', `')
  69. define(`ENDLIT', `')
  70. define(`BEGINDUMP', `')dnl
  71.  
  72. #********************************************************************
  73. #
  74. #macros used internally
  75. #
  76. #********************************************************************
  77. define(`repeat', 
  78. `ifelse(eval($2 <= 0), 1, , 
  79. `repeat(`$1', decr($2))'
  80. $1)')
  81.  
  82. define(`DECLAREMEM', 
  83. `define(`LABELON', 0)
  84. ifelse($2, _WORD_, `$1 DW ', 
  85. $2, _WORDn, `$1 DW $3',
  86. $2, _WORDr0, `$1 DW $3 DUP(0)',
  87. $2, _BYTE_, `$1 DB ', 
  88. $2, _BYTEn, `$1 DB $3',
  89. `$1 DB $3 DUP(0)')')
  90.  
  91. define(`REFmMEM', 
  92. `define(`LABELON', 0)
  93. ifelse($2, _WORD_, `$1 DW ', 
  94. $2, _WORDn, `$1 DW $3',
  95. $2, _WORDr0, `$1 DW $3 DUP(0)',
  96. $2, _BYTE_, `$1 DB ', 
  97. $2, _BYTEn, `$1 DB $3',
  98. `$1 DB $3 DUP(0)')')
  99.  
  100. #********************************************************************
  101. #
  102. #interrupt, task and monitor table creation macros
  103. #
  104. #********************************************************************
  105. define(`INTRS', 
  106. `
  107. INTRSEG SEGMENT PUBLIC
  108. dw $1, $2
  109. INTRSEG ENDS
  110. ')
  111.  
  112. define(`TASKS', 
  113. `
  114. TASKSEG SEGMENT PUBLIC
  115. dw $1, $2, $3
  116. TASKSEG ENDS
  117. ')
  118.  
  119. define(`MNTRS', 
  120. `
  121. MNTRSEG SEGMENT PUBLIC
  122. dw $1
  123. MNTRSEG ENDS
  124. ')
  125.  
  126. #********************************************************************
  127. #
  128. #RCSC virtual machine instruction set
  129. #
  130. #********************************************************************
  131. define(`ADD12',
  132. `ADD AX,BX')
  133. define(`ADD1n',
  134. `ADD AX,$1')
  135. define(`ADD21',
  136. `ADD BX,AX')
  137. define(`ADD2n',
  138. `ADD BX,$1')
  139. define(`ADDbpn',
  140. `ADD BYTE PTR [BX],$1')
  141. define(`ADDwpn',
  142. `ADD WORD PTR [BX],$1')
  143. define(`ADDm_',
  144. `ADD $1')
  145. define(`ADDSP',
  146. `ADD SP,$1')
  147. define(`AND12',
  148. `AND AX,BX')
  149. define(`ANEG1',
  150. `NEG AX')
  151. define(`ARGCNTn',
  152. `ifelse($1, 0, `XOR CL,CL', `MOV CL,$1')')
  153. define(`ASL12',
  154. `MOV CX,AX
  155. MOV AX,BX
  156. SAL AX,CL')
  157. define(`ASR12',
  158. `MOV CX,AX
  159. MOV AX,BX
  160. SAR AX,CL')
  161. define(`CALL1',
  162. `CALL AX')
  163. define(`CALLm',
  164. `CALL $1')
  165. define(`BYTE_', 
  166. `ifelse(LABELON, 1, `_BYTE_, $1)', ` DB ')')
  167. define(`BYTEn', 
  168. `ifelse(LABELON, 1, `_BYTEn, $1)', `DB $1')')
  169. define(`BYTEr0', 
  170. `ifelse(LABELON, 1, `_BYTEr0, $1)', `DB $1 DUP(0)')')
  171. define(`COM1',
  172. `NOT AX')
  173. define(`COMMAn',
  174. `,$1')
  175. define(`DBL1',
  176. `SHL AX,1')
  177. define(`DBL2',
  178. `SHL BX,1')
  179. define(`DECbp',
  180. `DEC BYTE PTR [BX]')
  181. define(`DECwp',
  182. `DEC WORD PTR [BX]')
  183. define(`DIV12',
  184. `CWD
  185. IDIV BX')
  186. define(`DIV12u',
  187. `XOR DX,DX
  188. DIV BX')
  189. define(`ENTER',
  190. `PUSH BP
  191. MOV BP,SP')
  192. define(`EQ10f',
  193. `OR AX,AX
  194. JE $+5
  195. JMP $1')
  196. define(`EQ12',
  197. `CALL __eq')
  198. define(`GE10f',
  199. `OR AX,AX
  200. JGE $+5
  201. JMP $1')
  202. define(`GE12',
  203. `CALL __ge')
  204. define(`GE12u',
  205. `CALL __uge')
  206. define(`GETb1m',
  207. `MOV AL,$1
  208. CBW')
  209. define(`GETb1mu',
  210. `MOV AL,$1
  211. XOR AH,AH')
  212. define(`GETb1p',
  213. `MOV AL,ifelse($1, 0, , $1)[BX]
  214. CBW')
  215. define(`GETb1pu',
  216. `MOV AL,ifelse($1, 0, , $1)[BX]
  217. XOR AH,AH')
  218. define(`GETb1s',
  219. `MOV AL,ifelse($1, 0, , $1)[BP]
  220. CBW')
  221. define(`GETb1su',
  222. `MOV AL,ifelse($1, 0, , $1)[BP]
  223. XOR AH,AH')
  224. define(`GETw1m',
  225. `MOV AX,$1')
  226. define(`GETw1m_',
  227. `MOV AX,')
  228. define(`GETw1n',
  229. `ifelse($1, 0, `XOR AX,AX', `MOV AX,$1')')
  230. define(`GETw1p',
  231. `MOV AX,ifelse($1, 0, , $1)[BX]')
  232. define(`GETw1s',
  233. `MOV AX,ifelse($1, 0, , $1)[BP]')
  234. define(`GETw2m',
  235. `MOV BX,$1')
  236. define(`GETw2n',
  237. `ifelse($1, 0, `XOR BX,BX', `MOV BX,$1')')
  238. define(`GETw2p',
  239. `MOV BX,ifelse($1, 0, , $1)[BX]')
  240. define(`GETw2s',
  241. `MOV BX,ifelse($1, 0, , $1)[BP]')
  242. define(`GT10f',
  243. `OR AX,AX
  244. JG $+5
  245. JMP $1')
  246. define(`GT12',
  247. `CALL __gt')
  248. define(`GT12u',
  249. `CALL __ugt')
  250. define(`INCbp',
  251. `INC BYTE PTR [BX]')
  252. define(`INCwp',
  253. `INC WORD PTR [BX]')
  254. define(`WORD_', 
  255. `ifelse(LABELON, 1, `_WORD_)', ` DW ')')
  256. define(`WORDn', 
  257. `ifelse(LABELON, 1, `_WORDn, $1)', `DW $1')')
  258. define(`WORDr0', 
  259. `ifelse(LABELON, 1, `_WORDr0, $1)', `DW $1 DUP(0)')')
  260. define(`JMPm',
  261. `JMP $1')
  262. define(`LABm',
  263. `$1')
  264. define(`LE10f',
  265. `OR AX,AX
  266. JLE $+5
  267. JMP $1')
  268. define(`LE12',
  269. `CALL __le')
  270. define(`LE12u',
  271. `CALL __ule')
  272. define(`LNEG1',
  273. `CALL __lneg')
  274. define(`LT10f',
  275. `OR AX,AX
  276. JL $+5
  277. JMP $1')
  278. define(`LT12',
  279. `CALL __lt')
  280. define(`LT12u',
  281. `CALL __ult')
  282. define(`MOD12',
  283. `CWD
  284. IDIV BX
  285. MOV AX,DX')
  286. define(`MOD12u',
  287. `XOR DX,DX
  288. DIV BX
  289. MOV AX,DX')
  290. define(`MOVE21',
  291. `MOV BX,AX')
  292. define(`MUL12',
  293. `IMUL BX')
  294. define(`MUL12u',
  295. `MUL BX')
  296. define(`NE10f',
  297. `OR AX,AX
  298. JNE $+5
  299. JMP $1')
  300. define(`NE12',
  301. `CALL __ne')
  302. define(`NEARm',
  303. ` DW $1')
  304. define(`OR12',
  305. `OR AX,BX')
  306. define(`PLUSn',
  307. `$1')
  308. define(`POINT1l',
  309. `MOV AX,OFFSET $1')
  310. define(`POINT1m',
  311. `MOV AX,OFFSET $1')
  312. define(`POINT1s',
  313. `LEA AX,ifelse($1, 0, , $1)[BP]')
  314. define(`POINT2m',
  315. `MOV BX,OFFSET $1')
  316. define(`POINT2m_',
  317. `MOV BX,OFFSET $1')
  318. define(`POINT2s',
  319. `LEA BX,ifelse($1, 0, , $1)[BP]')
  320. define(`POP2',
  321. `POP BX')
  322. define(`PUSH1',
  323. `PUSH AX')
  324. define(`PUSH2',
  325. `PUSH BX')
  326. define(`PUSHm',
  327. `PUSH $1')
  328. define(`PUSHp',
  329. `PUSH ifelse($1, 0, , $1)[BX]')
  330. define(`PUSHs',
  331. `PUSH ifelse($1, 0, , $1)[BP]')
  332. define(`PUT_m_',
  333. `MOV $1')
  334. define(`PUTbm1',
  335. `MOV $1,AL')
  336. define(`PUTbp1',
  337. `MOV [BX],AL')
  338. define(`PUTwm1',
  339. `MOV $1,AX')
  340. define(`PUTwp1',
  341. `MOV [BX],AX')
  342. define(`rDEC1',
  343. `repeat(`DEC AX', $1)')
  344. define(`rDEC2',
  345. `repeat(`DEC BX', $1)')
  346. define(`RETURN',
  347. `ifelse($1, 0, ,`MOV SP,BP')
  348. POP BP
  349. RET')
  350. define(`rINC1',
  351. `repeat(`INC AX', $1)')
  352. define(`rINC2',
  353. `repeat(`INC BX', $1)')
  354. define(`SUB_m_',
  355. `SUB $1')
  356. define(`SUB12',
  357. `SUB AX,BX')
  358. define(`SUB1n',
  359. `SUB AX,$1')
  360. define(`SUBbpn',
  361. `SUB BYTE PTR [BX],$1')
  362. define(`SUBwpn',
  363. `SUB WORD PTR [BX],$1')
  364. define(`SWAP12',
  365. `XCHG AX,BX')
  366. define(`SWAP1s',
  367. `POP BX
  368. XCHG AX,BX
  369. PUSH BX')
  370. define(`SWITCH',
  371. `CALL __switch')
  372. define(`XOR12',
  373. `XOR AX,BX')
  374. define(`CSCINIT',
  375. `CALL __cscinit')
  376. define(`ENTERM',
  377. `CLI')
  378. define(`EXITM',
  379. `STI')
  380.  
  381. divert
  382.